package com.eric.rabbitmq.topics;

import com.eric.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

public class ReceiveLog1 {
    public static final String EXCHANGE_NAME = "topic_logs";
    public static final String ROUTING_KEY = "*.orange.*";//匹配中间包含orange的三个单词

    public static void main(String[] args) throws Exception {
        //声明信道
        Channel channel = RabbitMqUtils.getChannel();
        //声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        //声明队列。
        String queueName ="console";
        channel.queueDeclare(queueName,false,false,false,null);
        //banding
        channel.queueBind(queueName, EXCHANGE_NAME, ROUTING_KEY);
        System.out.println("1等待接收消息");

        //接收消息
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("1打印消息:" + new String(message.getBody(), "UTF-8"));
        };
        channel.basicConsume(queueName, true, deliverCallback,consumerTag->{});
    }

}
